
var intro = new State();

var currentState = intro;

var frame1 =  new Image();
frame1.src = "metroid/metroidanimation.gif";

var animation = new Image();
animation.src = "metroid/metroidanimation.gif";

var imageScale = 0;
var posX = 0;
var posY = 0;
var width = 0;
var height = 0;
var seconds = 3;
intro.init = function()
{
 
	 
    if(!muted)
    music.play();
    this.initialized = true;
    this.finished = false;
   //  document.body.style.imageRendering = "crisp-edges";
   // document.getElementById("maincanvas").style.display = "none";
   //  document.body.style.backgroundImage = "url('metroid/metroidanimation.gif'), url('metroid/metroidfiller.gif')";
   //   // document.body.style.backgroundPosition = "center";
   //   document.body.style.backgroundRepeat = "no-repeat, repeat-x";
   //   document.body.style.backgroundSize = "contain, contain";
};

intro.update = function()
{ 
	// if(imageScale==0 && frame1.height>0)
	// {
		var h = canvasBuffer.height;
	    var w = canvasBuffer.width;
	    var ih = frame1.height;
	    var iw = frame1.width;

	    var scaleX = h/ih;
	    var scaleY = w/iw; 
	    console.log(h,ih, w, iw);
	    if(scaleX >scaleY)
	    {
	    	imageScale = scaleY;
	    }
	    else
	    {
	    	imageScale = scaleX;
	    }
	 	width = frame1.width *imageScale;
	 	height = frame1.height * imageScale;
	 	posX= (w/2)-(width/2);
    // }
    if(time > seconds && !this.finished)
    { 
    	console.log("finished intro");
        hitLink("home.html", game.init);
        this.finished = true;
    } 
    var frame = new Image();
    frame.src = "metroid/animation/tmp-"+Math.floor(time*10);
    contextBuffer.drawImage(frame, posX, posY, width,height);
 
//    essentially, our frame swap
 	context.drawImage(canvasBuffer, 0 , 0);

};
